package Reflection;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.lang.reflect.Field;

public class Project {

    public static void business(Object obj) throws IllegalAccessException, FileNotFoundException {
        //创建I/O对象，可追加
        PrintStream ps = new PrintStream(new FileOutputStream("D:\\software\\code\\2023_java\\2023_java_code\\code_24_5_3\\src\\Reflection\\Text.text",true));

        //先获取class对象
        Class c = obj.getClass();
        ps.println("==============" + c.getName() + "==============");

        //再获取全部成员变量
        Field[] fields = c.getDeclaredFields();
        //将其进行遍历
        for (Field field : fields) {
            String name = field.getName();
            String value = field.get(obj) + "";
            ps.println(name + " => " + value);
        }

        //记得关闭资源
        ps.close();
    }
}
